//
//  MCBaseLotteryHallViewController.m
//  TLYL
//
//  Created by miaocai on 2017/6/7.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCBaseLotteryHallViewController.h"
#import "MCPullMenuViewController.h"
#import "MCPullMenuPresentationController.h"
#import "MCPickBottomButton.h"
#import "UIImage+Extension.h"
#import "MCMoneyPopView.h"
#import "MCMSPopView.h"
#import "NSString+Helper.h"
#import "MCWFExplainViewController.h"
#import "MCMoreNavView.h"
#import "MCGameRecordViewController.h"
#import "MCGetplayawardModel.h"
#import "MCMaxbonusModel.h"
#import "MCIssueModel.h"
#import "MCLotteryID.h"
#import "MCMaxbonusModel.h"
#import "MCUserMoneyModel.h"
#import "MCGetMerchantInfoModel.h"
#import "MCDataTool.h"
#import "MCMineInfoModel.h"
#import "MCHistoryIssueDetailAPIModel.h"
#import "MCChaseNumberViewController.h"
#import "MCPickNumberViewController.h"
#import "MClotteryTrendChartModel.h"
#import "MCLotteryRecordViewController.h"
#import "MCPayWebViewController.h"
#import "MCMmcIssueDetailAPIModel.h"
#import "MCPullMenuTool.h"
@interface MCBaseLotteryHallViewController ()
<MCPullMenuDelegate>

#pragma mark - property
/**定时器*/
@property(nonatomic,strong) NSTimer *timer;
/**底部视图*/
@property (nonatomic,weak) UIView *bottomView;
//金额label
@property (nonatomic,weak) UILabel *zhuLabel;
//若中奖金额label
@property (nonatomic,weak) UILabel *botomLabel;
/**期号刷新*/
@property (nonatomic,weak) UIButton *btnRefreashIssueNumber;
/**期号string*/
@property (nonatomic,strong) NSString *lastString;
/**随机按钮状体*/
@property (nonatomic,assign) BOOL randomBtnSelected;
/**随机按钮*/
@property (nonatomic,weak) UIButton *randomBtn;

/**投注页右上角功能按钮View*/
@property (nonatomic,weak)MCMoreNavView * moreNavView;
/**isShowMoreBtn 是否展示按钮*/
@property (nonatomic,assign)BOOL isShowMoreBtn;
/**playawardModel模型的强引用*/
@property (nonatomic,strong)MCGetplayawardModel *playawardModel;
//单挑
@property (nonatomic,strong)MCMaxbonusModel *bonusModel;
//旗号
@property (nonatomic,strong)MCIssueModel *issueModel;

//@property (nonatomic,strong)MCGetMerchantInfoModel * getMerchantInfoModel;

//期号加载菊花
@property (nonatomic, strong) UIActivityIndicatorView * activityIndicator;
//追号完成后  余额进行刷新
@property (nonatomic, strong) MCUserMoneyModel * userMoneyModel;
//倒计时
@property (nonatomic,weak) UIView *bgtopView;
//右上蒙层
@property (nonatomic,weak) UIView *cloverView;
//下方蒙层
@property (nonatomic,weak) UIView *cover;
@property (nonatomic,weak)UIButton *addBtn;

@property (nonatomic, strong)MClotteryTrendChartModel * lotteryTrendChartModel;
@property (nonatomic, strong)MCHistoryIssueDetailAPIModel * historyIssueDetailAPIModel;
@property (nonatomic, strong) MCMmcIssueDetailAPIModel *mmcHistoryIssueDetailAPIModel;
@property (nonatomic, strong) NSTimer *historyTimer;
@property (nonatomic,assign)BOOL isPopPresentedController;
@property (nonatomic,weak) UILabel *labelDataDaojishi ;
//@property (nonatomic ,strong) MBProgressHUD *hud;
@end

@implementation MCBaseLotteryHallViewController

//- (MBProgressHUD *)hud{
//    if (_hud == nil) {
//        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.historyView animated:YES];
//        hud.color = [UIColor clearColor];
//
//        _hud = hud;
//    }
//    return _hud;
//}

#pragma mark - life cycle
- (void)viewDidLoad {
    [[UIActivityIndicatorView appearance] setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = [UIColor darkGrayColor];
    [super viewDidLoad];
 
    [self setUpUI];
    //为导航栏添加右侧按钮(+更多)
    [self addNavRightBtn];
    
    [self  setUpTopDragDownView];
    
    [self setUpTopTimerView];
    //底部按钮
    [self setUpBottomView];

    [self loadData];

}



-(void)relayOutHistoryView:(NSNotification *)notification{
    NSString * CzNum = notification.object;
    NSArray *arrT = [CzNum componentsSeparatedByString:@","];
    self.historyView.lastHistoryBallArray=arrT;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(relayOutHistoryView:) name:@"MCMCBaseLotteryHallViewControllerRelayOutHistoryView" object:nil];
    
    
    //清空注单信息
    
    //清空注单信息
    if (self.isPopPresentedController == YES) {
        
    }else{
        self.baseWFmodel.stakeNumber = 0;
        self.baseWFmodel.payMoney = 0;
        [self setBetListMarry];
    }
    [self registerNotifacation];
        //查询余额
    __weak typeof(self) weakSelf = self;
    MCUserMoneyModel * userMoneyModel=[MCUserMoneyModel sharedMCUserMoneyModel];
    if (userMoneyModel.isNeedLoad||userMoneyModel.LotteryMoney.length<1) {
        
        [userMoneyModel refreashDataAndShow];
        self.userMoneyModel=userMoneyModel;
        
        userMoneyModel.callBackSuccessBlock = ^(id manager) {
            weakSelf.userMoneyModel.FreezeMoney=manager[@"FreezeMoney"];
            weakSelf.userMoneyModel.LotteryMoney=manager[@"LotteryMoney"];
            
            weakSelf.labelBonusDetail.attributedText =[NSString attrbutstring:[NSString stringWithFormat:@"余额:%@",[MCMathUnits GetMoneyShowNum:[MCUserMoneyModel sharedMCUserMoneyModel].LotteryMoney]]];
           
        };
        
    }else{
        weakSelf.labelBonusDetail.attributedText = [NSString attrbutstring:[NSString stringWithFormat:@"余额:%@",[MCMathUnits GetMoneyShowNum:[MCUserMoneyModel sharedMCUserMoneyModel].LotteryMoney]]];
    }
    
    [self loadIssueData:^(BOOL result) {
        if (!result) {
//            [self openFailedIssue];
        }
    }];
  

    
    /*
     * 追号跳转
     */
    
    if ([self isKindOfClass:[MCChaseNumberViewController class]]) {
        MCUserDefinedLotteryCategoriesModel *model = [MCUserDefinedLotteryCategoriesModel GetMCUserDefinedLotteryCategoriesModelWithCZID:self.baseWFmodel.LotteryID];
        MCPickNumberViewController *pickVc = [[MCPickNumberViewController alloc] init];
        pickVc.lotteriesTypeModel = model;
        pickVc.navigationItem.title = [MCLotteryID getLotteryCategoriesNameByID:self.baseWFmodel.LotteryID];
        [self.navigationController pushViewController:pickVc animated:YES];
    }

    [self loadFistData];
    
    if ([self.baseWFmodel.LotteryID isEqualToString:@"50"] == YES) {
        [self.addBtn setTitle:@"立即开奖" forState:UIControlStateNormal];
    } else {
        [self.addBtn setTitle:@"一键投注" forState:UIControlStateNormal];
    }

   
    
}

- (void)setUpHistoryTimer{
    [self stopHistoryTimer];
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(loadHistoryIssueData) userInfo:nil repeats:YES];
    self.historyTimer = timer;
    [[NSRunLoop mainRunLoop ] addTimer:timer forMode:NSRunLoopCommonModes];
   
}



- (void)stopHistoryTimer{
    //关闭定时器

    [self.historyTimer setFireDate:[NSDate distantFuture]];

    [self.historyTimer invalidate];

    self.historyTimer = nil;
    
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    if ([self.navigationController.topViewController isKindOfClass:[MCGameRecordViewController class]]||[self.navigationController.topViewController isKindOfClass: [MCWFExplainViewController class]]||[self.navigationController.topViewController isKindOfClass:         [MCPayWebViewController class]]) {
        
        self.isPopPresentedController = YES;
    } else {
        self.isPopPresentedController = NO;
        [self stopTimer];
        [self stopHistoryTimer];
        [self.alertView hideStackWindow];
        [self relayOutAlertViewData];
        self.issueModel = nil;
        _mmcHistoryIssueDetailAPIModel = nil;
        _historyIssueDetailAPIModel =  nil;
    }
  
    
}


- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark --------------------- setUpUI
- (void)addNavRightBtn {
    /*
     * 导航栏按钮
     */
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, MC_REALVALUE(20), MC_REALVALUE(20));
    [rightBtn addTarget:self action:@selector(moreBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setImage:[UIImage imageNamed:@"添加"] forState:UIControlStateNormal];
    UIBarButtonItem *rewardItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceItem.width = -7;
    self.navigationItem.rightBarButtonItems = @[spaceItem,rewardItem];
    

  
}
- (void)setUpTopDragDownView{
    /*
     *  玩法名称
     */
    
    UIView * topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, G_SCREENWIDTH, MC_REALVALUE(50))];
    [self.view addSubview:topView];
    topView.backgroundColor = [UIColor whiteColor];
    
    UIButton *btnPCatergy = [[UIButton alloc] init];
    [topView addSubview:btnPCatergy];
    btnPCatergy.frame = CGRectMake(0, 0, MC_REALVALUE(134), MC_REALVALUE(50));
    
    [btnPCatergy setTitleColor:RGB(0, 0, 0) forState:UIControlStateNormal];
    btnPCatergy.titleEdgeInsets = UIEdgeInsetsMake(0,-25, 0, 0);
    btnPCatergy.titleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(14)];
    btnPCatergy.titleLabel.textAlignment = NSTextAlignmentCenter;
    [btnPCatergy addTarget:self action:@selector(btnPCatergyClick:) forControlEvents:UIControlEventTouchUpInside];
    self.btnPCatergy = btnPCatergy;
    UIImageView *imgPCatergy = [[UIImageView alloc] init];
    imgPCatergy.image =[UIImage imageNamed:@"touzhu-xiala"];
    [btnPCatergy addSubview:imgPCatergy];
    [imgPCatergy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(btnPCatergy).offset(-1);
        make.width.equalTo(@(MC_REALVALUE(15)));
        make.height.equalTo(@(MC_REALVALUE(8)));
        make.centerY.equalTo(btnPCatergy);
    }];

    UIView * view_line=[[UIView alloc]init];
    view_line.backgroundColor=RGB(239, 239, 239);
    [btnPCatergy addSubview:view_line];
    [view_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(MC_REALVALUE(40)));
        make.width.equalTo(@(MC_REALVALUE(1)));
        make.right.equalTo(btnPCatergy);
    }];
    
    UILabel *labelhistory = [[UILabel alloc] init];
    labelhistory.text = @"最新开奖";
    labelhistory.textAlignment = NSTextAlignmentCenter;
    labelhistory.numberOfLines = 2;
    [topView addSubview:labelhistory];
    labelhistory.font = [UIFont systemFontOfSize:MC_REALVALUE(11)];
    [labelhistory mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView);
        make.left.equalTo(btnPCatergy.mas_right).offset(MC_REALVALUE(10));
        make.width.equalTo(@(MC_REALVALUE(30)));
        
    }];
    
 
    labelhistory.textColor = RGB(68, 68, 68);
    

    
    /*
     * 近期开奖
     */
    UIButton *btnKaiJiang = [[UIButton alloc] init];
    [topView addSubview:btnKaiJiang];
    [btnKaiJiang setImage:[UIImage imageNamed:@"touzhu-xiala"] forState:UIControlStateNormal];
    [btnKaiJiang addTarget:self action:@selector(btnKaiJiangClick:) forControlEvents:UIControlEventTouchUpInside];
    self.btnKaiJiang = btnKaiJiang;
    [btnKaiJiang mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(topView);
        make.height.equalTo(@(MC_REALVALUE(50)));
        make.centerY.equalTo(topView);
        make.width.equalTo(@(MC_REALVALUE(30)));
    }];
    
    
    
    MCHistoryCollectionView *historyView = [[MCHistoryCollectionView alloc] init];
    [topView addSubview:historyView];
    [historyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView);
        make.top.bottom.equalTo(topView);
        make.left.equalTo(labelhistory.mas_right).offset(MC_REALVALUE(0));
        make.right.equalTo(btnKaiJiang.mas_left).offset(MC_REALVALUE(0));

    }];
    
    UILabel *label = [[UILabel alloc] init];
    [topView addSubview:label];
    label.text = @"暂无数据";
    label.textColor = RGB(68, 68, 68);
    label.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView);
        make.top.bottom.equalTo(topView);
        make.left.equalTo(labelhistory.mas_right).offset(MC_REALVALUE(0));
        make.right.equalTo(btnKaiJiang.mas_left).offset(MC_REALVALUE(0));
        
    }];
    label.hidden = YES;
    self.noDatalabel = label;
    self.historyView = historyView;
    UIButton * btn =[[UIButton alloc]init];
    [topView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView);
        make.left.equalTo(btnPCatergy.mas_right).offset(MC_REALVALUE(10));
        make.width.equalTo(@(MC_REALVALUE(200)));
    }];
    [btn addTarget:self action:@selector(btnKaiJiangClick:) forControlEvents:UIControlEventTouchUpInside];
}


- (void)setUpTopTimerView{
    /*
     * 倒计时栏
     */
    UIView *bgtopView = [[UIView alloc] init];
    [self.view addSubview:bgtopView];
    bgtopView.frame = CGRectMake(0, MC_REALVALUE(50), G_SCREENWIDTH, MC_REALVALUE(40));
    bgtopView.clipsToBounds = YES;
    bgtopView.backgroundColor = RGB(239,239,239);
    self.bgtopView = bgtopView;
    bgtopView.userInteractionEnabled = YES;
    
    UIImageView *imgDaojishi = [[UIImageView alloc] init];
    [bgtopView addSubview:imgDaojishi];
    imgDaojishi.image = [UIImage imageNamed:@"djs"];
    [imgDaojishi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bgtopView).offset(MC_REALVALUE(5));
        make.left.equalTo(@(MC_REALVALUE(13)));
        make.height.equalTo(@(MC_REALVALUE(13)));
        make.width.equalTo(@(MC_REALVALUE(11)));
    }];
    
    UILabel *labelDataDaojishi = [[UILabel alloc] init];
    [bgtopView addSubview:labelDataDaojishi];
    self.labelDataDaojishi = labelDataDaojishi;
    [labelDataDaojishi sizeToFit];
    labelDataDaojishi.font = [UIFont boldSystemFontOfSize:MC_REALVALUE(12)];
    [labelDataDaojishi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imgDaojishi);
        make.left.equalTo(imgDaojishi.mas_right).offset(MC_REALVALUE(0));
        
    }];
    labelDataDaojishi.textAlignment = NSTextAlignmentLeft;
    self.btnDaojishi = labelDataDaojishi;
    labelDataDaojishi.textColor = RGB(68, 68, 68);

    UIButton * btnRefreashIssueNumber =[[UIButton alloc]init];
    [btnRefreashIssueNumber setTitle:@"点击刷新" forState:UIControlStateNormal];
    btnRefreashIssueNumber.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [btnRefreashIssueNumber setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
    [labelDataDaojishi addSubview:btnRefreashIssueNumber];
    _btnRefreashIssueNumber=btnRefreashIssueNumber;
    _btnRefreashIssueNumber.hidden=YES;
    [_btnRefreashIssueNumber addTarget:self
                                action:@selector(loadIssueData:) forControlEvents:UIControlEventTouchUpInside];
    
    
    MCUserMoneyModel * userMoneyModel=[MCUserMoneyModel sharedMCUserMoneyModel];
    UILabel *labelBonusDetail = [[UILabel alloc] init];
    labelBonusDetail.text =  [NSString stringWithFormat:@"%@",[MCMathUnits GetMoneyShowNum:userMoneyModel.LotteryMoney]];
    labelBonusDetail.textColor = [UIColor blackColor];
    labelBonusDetail.textAlignment = NSTextAlignmentLeft;
    [bgtopView addSubview:labelBonusDetail];
    labelBonusDetail.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.labelBonusDetail=labelBonusDetail;
    
    labelBonusDetail.lineBreakMode = NSLineBreakByTruncatingTail;
    [labelBonusDetail addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)]];
    labelBonusDetail.userInteractionEnabled = YES;
    
    [labelBonusDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(labelDataDaojishi.mas_right);

        make.centerY.equalTo(labelDataDaojishi);
//        make.width.equalTo(@(110));
    }];
    
}
/*
 * 底部的view
 */

- (void)setUpBottomView{
    
    MCAlertView *alertView = [MCAlertView alertInstance];
    [self.view addSubview:alertView];
    self.alertView = alertView;
    __weak typeof(self) weakself = self;
    alertView.fandianBlock = ^{
        [weakself cover];
        
    };
    alertView.moshiBlock = ^{
        [weakself cover];
    };
    
    UIView *bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    self.bottomView = bottomView;
    if (G_SCREENHEIGHT == 812) {
        self.bottomView.frame = CGRectMake(0, G_SCREENHEIGHT- 49 -64 - 40, G_SCREENWIDTH, 49 + 20);
    } else {
        self.bottomView.frame = CGRectMake(0, G_SCREENHEIGHT- 49 -64 - 20, G_SCREENWIDTH, 49 + 20);
    }
    UIImageView *imgV = [[UIImageView alloc] init];
    [bottomView addSubview:imgV];
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(bottomView);
        make.right.equalTo(bottomView);
        make.height.equalTo(@(69));
    }];
    
    imgV.image = [UIImage imageNamed:@"touzhu-dikuang"];
    imgV.userInteractionEnabled = YES;
    UIButton *addBtn = [[UIButton alloc] init];
    [imgV addSubview:addBtn];
 
    self.addBtn = addBtn;
    [addBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    addBtn.titleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(14)];
    addBtn.tag = 1997;
    [addBtn addTarget:self action:@selector(bottomViewBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(imgV);
        make.top.equalTo(imgV).offset(MC_REALVALUE(10));
        make.width.equalTo(@(MC_REALVALUE(90)));
    }];
    
    UIButton *buyBtn = [[UIButton alloc] init];
    [imgV addSubview:buyBtn];
    [buyBtn setTitle:@"添加投注" forState:UIControlStateNormal];
    buyBtn.tag = 1996;
    [buyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    buyBtn.titleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(14)];
    [buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgV);
        make.top.equalTo(imgV).offset(MC_REALVALUE(10));
        make.width.equalTo(@(MC_REALVALUE(90)));
    }];
    [buyBtn addTarget:self action:@selector(bottomViewBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *botomLabel = [[UILabel alloc] init];
    botomLabel.backgroundColor = [UIColor clearColor];
    [bottomView addSubview:botomLabel];
    botomLabel.frame = CGRectMake(0, 48, G_SCREENWIDTH, 20);
    botomLabel.textAlignment = NSTextAlignmentCenter;
    botomLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    self.botomLabel = botomLabel;
    botomLabel.textColor = RGB(255, 255, 255);
    
   
    
    UILabel *zhuLabel = [[UILabel alloc] init];
    zhuLabel.textColor = [UIColor whiteColor];
    zhuLabel.textAlignment = NSTextAlignmentCenter;
    
    zhuLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    zhuLabel.textAlignment = NSTextAlignmentCenter;
    
    [imgV addSubview:zhuLabel];
    zhuLabel.textAlignment = NSTextAlignmentCenter;
    [zhuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(buyBtn.mas_top).offset(MC_REALVALUE(5));
        make.left.equalTo(buyBtn.mas_right);
        make.right.equalTo(addBtn.mas_left);
        make.height.equalTo(@(29));
    }];
    self.zhuLabel = zhuLabel;
    
    
  
    
    
    
    /*
     * 投注页右上角功能按钮
     */
    UIView *clover = [[UIView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:clover];
    self.cloverView = clover;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCoverView)];
    [clover addGestureRecognizer:tap];
    clover.backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.5];
    clover.hidden = YES;
    MCMoreNavView * moreNavView=[[MCMoreNavView alloc]init];
    [clover addSubview:moreNavView];
    moreNavView.frame=CGRectMake(G_SCREENWIDTH-WIDTH_MCMoreNav, 0, WIDTH_MCMoreNav, 0);
    _moreNavView=moreNavView;
    [_moreNavView.btn_PlayRecord addTarget:self action:@selector(action_PlayRecord) forControlEvents:UIControlEventTouchUpInside];
    [_moreNavView.btn_WFexplain addTarget:self action:@selector(action_WFexplain) forControlEvents:UIControlEventTouchUpInside];
    [_moreNavView.btn_TrendChart addTarget:self action:@selector(action_TrendChart) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark --------------------点击事件touch event
//投注页右上角功能按钮
- (void)moreBtnClick:(UIButton *)btn{
    
    if (_isShowMoreBtn) {
        _isShowMoreBtn=NO;
    }else{
        _isShowMoreBtn=YES;
    }
    
    if (_isShowMoreBtn) {
        self.cloverView.hidden = NO;
        if ([self.baseWFmodel.LotteryID isEqualToString:@"50"]) {
            
            _moreNavView.frame=CGRectMake(G_SCREENWIDTH-WIDTH_MCMoreNav, 0, WIDTH_MCMoreNav, 90);
            _moreNavView.btn_TrendChart.hidden=YES;
        }else{
            _moreNavView.frame=CGRectMake(G_SCREENWIDTH-WIDTH_MCMoreNav, 0, WIDTH_MCMoreNav, HEIGHT_MCMoreNav);
            _moreNavView.btn_TrendChart.hidden=NO;
        }
        
    }else{
        
        self.cloverView.hidden = YES;
        _moreNavView.frame=CGRectMake(G_SCREENWIDTH-WIDTH_MCMoreNav, 0, WIDTH_MCMoreNav, 0);
    }
    
    
}
//跳转游戏记录
-(void)action_PlayRecord{
    
    [UIView animateWithDuration:0.2 animations:^{
        
        _moreNavView.frame=CGRectMake(G_SCREENWIDTH-WIDTH_MCMoreNav, 0, WIDTH_MCMoreNav, 0);
        
    } completion:^(BOOL finished) {
        _isShowMoreBtn=NO;
        self.cloverView.hidden = YES;
        MCGameRecordViewController * vc = [[MCGameRecordViewController alloc]init];
        vc.isNeedBackControl=YES;
        vc.czName=self.baseWFmodel.czName;
        vc.lotteryCode=self.baseWFmodel.LotteryID;
        [self.navigationController pushViewController:vc animated:YES];
    }];
    
}

//跳转玩法说明
-(void)action_WFexplain{
    [UIView animateWithDuration:0.2 animations:^{
        
        _moreNavView.frame=CGRectMake(G_SCREENWIDTH-WIDTH_MCMoreNav, 0, WIDTH_MCMoreNav, 0);
        
    } completion:^(BOOL finished) {
        _isShowMoreBtn=NO;
        self.cloverView.hidden = YES;
        MCWFExplainViewController * vc = [[MCWFExplainViewController alloc]init];
        vc.baseWFmodel=self.baseWFmodel;
        [self.navigationController pushViewController:vc animated:YES];
    }];
    
}

//跳转走势图
-(void)action_TrendChart{
    
    MClotteryTrendChartModel * lotteryTrendChartModel = [[MClotteryTrendChartModel alloc]initWithDic:@{@"lotteryId":self.baseWFmodel.LotteryID}];
    self.lotteryTrendChartModel = lotteryTrendChartModel;
    [lotteryTrendChartModel refreashDataAndShow];
    
    __weak __typeof__ (self) wself = self;
    lotteryTrendChartModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSString *errorCode) {
        wself.isShowMoreBtn=NO;
        wself.cloverView.hidden = YES;
        
    };
    
    lotteryTrendChartModel.callBackSuccessBlock = ^(id manager) {
        wself.isShowMoreBtn=NO;
        wself.cloverView.hidden = YES;
        NSDictionary * dic = manager;
        NSString * url = dic[@"LotteryTrendChartUrl"];
        if (url) {
            
            MCPayWebViewController * vc = [[MCPayWebViewController alloc]init];
            vc.url=url;
            vc.strTitle=self.baseWFmodel.czName;
            [wself.navigationController pushViewController:vc animated:YES];
           
            
        }
        
    };
}


/** 玩法*/
- (void)btnPCatergyClick:(UIButton *)btn{
    __weak typeof(self) weakSelf = self;
    MCPullMenuViewController *VC = [[MCPullMenuViewController alloc]init];
    VC.delegate=self;
    /*
     * 传入彩种ID
     */
    VC.lotteriesTypeModel = self.lotteriesTypeModel;
    MCPullMenuPresentationController *PC = [[MCPullMenuPresentationController alloc] initWithPresentedViewController:VC presentingViewController:self];
    PC.goBackBlock = ^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    };
    PC.type=MCPullMenuCZListType;
    VC.transitioningDelegate = PC;
    [self presentViewController:VC animated:YES completion:NULL];
}

//点击小球调用
- (void)ballBtnClick{
    self.randomBtnSelected = NO;
    //延迟调用的原因：self.baseWFmodel里面小球的选中信息没有及时更新过来，导致显示注数不对
    [self performSelector:@selector(delayMethod) withObject:nil afterDelay:0.05];
}
/** 历史*/
- (void)btnHistroyClick:(MCPickBottomButton *)btn{
    
}

- (void)bottomViewBtnClick:(MCPickBottomButton *)btn{
    
    if (btn.tag == 1999) {//机选
        [self randomBtnClick];
    }else if (btn.tag == 1998) {//清空
        [self clearAllButtonClick];
        if (self.isDanShi) {
        }else{
            [self.alertView hideStackWindow];
        }
    }else if (btn.tag == 1997) {
        //快速投注
        [self conferencePayTheSelectedNumbers];
    }else if (btn.tag == 1996) {
        //添加号码
        [self addNumberToShoppingCar:YES];
        
    }
}
/** 近期开奖*/
-(void)btnKaiJiangClick:(UIButton *)btn{
    [self loadHistoryIssueData];
    [self KaiJiangClick];
}
-(void)KaiJiangClick{};
/*
 * 余额按钮点击弹出框
 */

- (void)tap{
    [SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"余额：%@元",[MCMathUnits GetMoneyShowNum:[MCUserMoneyModel sharedMCUserMoneyModel].LotteryMoney]]];
}


/*
 * 蒙层的点击
 */


- (void)tapcover{
    [self.cover removeFromSuperview];
    self.alertView.isShowMSPop=NO;
    self.alertView.isShowMoneyPop=NO;
    MCMSPopView * pView=[MCMSPopView alertInstance];
    [pView hideModelWindow];
    MCMoneyPopView * p1View=[MCMoneyPopView alertInstance];
    [p1View hideModelWindow];
}

/*
 * 蒙层
 */

- (UIView *)cover{
    if (_cover == nil) {
        UIView *cover = [[UIView alloc] initWithFrame:self.view.bounds];
        cover.backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4];
        [self.view addSubview:cover];
        [cover addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapcover)]];

        self.cover = cover;
    }
    return _cover;
}


/*
 * 投注页右上角功能按钮
 */
- (void)tapCoverView{
    self.cloverView.hidden = YES;
}
#pragma mark --------------------- registerNotifacation
- (void)registerNotifacation{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBorardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mcStackeUnitsGetBallWF:) name:PickViewControllerBallStatusChangedNSNotification object:nil];
    
    /*
     * 单式玩法
     */
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideStackWindowss) name:PickViewControllerDanShiTextFieldEdtingNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ballBtnClick) name:PickViewCellBallClickedNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(action_YuanJiaoFen:) name:MCActionYuanJiaoFen object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(action_Multiple:) name:MCActionMultiple object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setUserSelectedRebate:) name:McSelectedBetRebate object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadIssue) name:@"MCloadIssueNumber" object:nil];
    
    
    
}


/*
 *底部输入框事件
 */

- (void)hideStackWindowss{
    if (self.alertView.hidden == YES) {
        return;
    } else {
        if (self.isDanShi) {
            return;
        }
        [self.alertView hideStackWindow];
    }
    
}

/*
 * 键盘处理
 */

- (void)keyBorardWillShow:(NSNotification *)noti{
    NSDictionary *dic = noti.userInfo;
    CGRect rect = [dic[@"UIKeyboardBoundsUserInfoKey"] CGRectValue];
    CGFloat h  = 20;
    if (IS_iPhoneX) {
        h  = 10;
    }
    self.alertView.frame = CGRectMake(0, G_SCREENHEIGHT - rect.size.height - kTabBarHeight - 60 -64, G_SCREENWIDTH, 49 + 60);
    self.bottomView.frame = CGRectMake(0, G_SCREENHEIGHT- rect.size.height -64 - kTabBarHeight - h , G_SCREENWIDTH, 49 + 20);
    [self.alertView popViewHidden];
}

- (void)keyBoardWillHide:(NSNotification *)noti{
    CGFloat h  = 20;
    if (IS_iPhoneX) {
        h  = 10;
    }
    self.alertView.frame = CGRectMake(0, G_SCREENHEIGHT - kTabBarHeight - 60 -64, G_SCREENWIDTH, 49 + 60);
    self.bottomView.frame = CGRectMake(0, G_SCREENHEIGHT- kTabBarHeight -64 - h, G_SCREENWIDTH, 49 + 20);
    
}

#pragma mark --------------------- 数据处理

-(void)delayMethod{
    MCBallPropertyModel *model =  [MCStakeUntits GetBallPropertyWithWFModel:self.baseWFmodel];
    [[NSNotificationCenter defaultCenter] postNotificationName:PickViewControllerBallStatusChangedNSNotification object:nil userInfo:@{@"ballModel":model}];
}


//修改了注数
- (void)mcStackeUnitsGetBallWF:(NSNotification *)noti{
    //    NSLog(@"%p",self);
    NSDictionary *dic = noti.userInfo;
    MCBallPropertyModel * model = dic[@"ballModel"];
    
    MCBallPropertyModel * model1 = dic[@"danshiModel"];
    if (model1 == nil) {
        if (model.stakeNumber >=1) {
            [self.alertView showStackWindow];
        }else{
            if (self.isDanShi) {
            }else{
                [self.alertView hideStackWindow];
            }
        }
        
        self.baseWFmodel.stakeNumber=model.stakeNumber;
        [self relayOutAlertViewData];
        
    } else {
        if (model1.stakeNumber>=1) {
            [self.alertView showStackWindow];
        }else{
            if (self.isDanShi) {
            }else{
                [self.alertView hideStackWindow];
            }
        }
        self.baseWFmodel.stakeNumber=model1.stakeNumber;
        [self relayOutAlertViewData];
    }
    
    
    
}
//修改了元角分
- (void)action_YuanJiaoFen:(NSNotification *)noti{
    NSDictionary *dic = noti.userInfo;
    NSString * type= dic[@"type"];
    
    if ([type isEqualToString:@"元  模式"]) {
        self.baseWFmodel.yuanJiaoFen=1;
    }else if ([type isEqualToString:@"角  模式"]){
        self.baseWFmodel.yuanJiaoFen=0.1;
    }else if ([type isEqualToString:@"分  模式"]){
        self.baseWFmodel.yuanJiaoFen=0.01;
    }else if ([type isEqualToString:@"厘  模式"]){
        self.baseWFmodel.yuanJiaoFen=0.001;
    }

    
    /*
     * 2018年09月21日-圆角分需求
     */
    self.yuanJiaoFenType = type;
    [MCPullMenuTool SaveSelectedLotteryID:self.lotteriesTypeModel.LotteryID  andYuanJiaoFen:self.yuanJiaoFenType];
    
    [self relayOutAlertViewData];
    
}

//修改了倍数
- (void)action_Multiple:(NSNotification *)noti{
    NSDictionary *dic = noti.userInfo;
    NSString * multiple= dic[@"multiple"];
    self.baseWFmodel.multiple=[multiple intValue];
    [self relayOutAlertViewData];
}

//刷新弹框数据
-(void)relayOutAlertViewData{
    [self.cover removeFromSuperview];
    if ( (self.baseWFmodel.yuanJiaoFen-(int)self.baseWFmodel.yuanJiaoFen)==0) {

        
       double money = self.baseWFmodel.stakeNumber*2*self.baseWFmodel.yuanJiaoFen*self.baseWFmodel.multiple;
       
        self.baseWFmodel.payMoney = [MCMathUnits doubleWithdecimalNumber:money];
        
    } else {


       double money =  self.baseWFmodel.stakeNumber*2*self.baseWFmodel.yuanJiaoFen*self.baseWFmodel.multiple;
       
            self.baseWFmodel.payMoney = [MCMathUnits doubleWithdecimalNumber:money];
        
    }
    
  
//    zhuLabel
    self.zhuLabel.text = [NSString stringWithFormat:@"%d注，%@元",self.baseWFmodel.stakeNumber,GetRealFloatNum(self.baseWFmodel.payMoney)];

    
    
    if (self.baseWFmodel.maxAwardAmount&&self.baseWFmodel.minAwardAmount) {
        
        MCMoneyModel * MaxModel= MCGetBouns(self.baseWFmodel.maxAwardAmount, self.baseWFmodel.userSelectedRebate, self.baseWFmodel.yuanJiaoFen, self.baseWFmodel.multiple, self.baseWFmodel.payMoney);

        MCMoneyModel * MinModel= MCGetBouns(self.baseWFmodel.minAwardAmount, self.baseWFmodel.userSelectedRebate, self.baseWFmodel.yuanJiaoFen, self.baseWFmodel.multiple, self.baseWFmodel.payMoney);
 
        self.botomLabel.text = [NSString stringWithFormat:@"若中奖，奖金%@~%@元,可盈利%@~%@元",MinModel.bouns,MaxModel.bouns,MinModel.yinli,MaxModel.yinli];
        
        
        
    }else if (self.baseWFmodel.maxAwardAmount){
        
        MCMoneyModel * MaxModel= MCGetBouns(self.baseWFmodel.maxAwardAmount, self.baseWFmodel.userSelectedRebate, self.baseWFmodel.yuanJiaoFen, self.baseWFmodel.multiple, self.baseWFmodel.payMoney);
        self.baseWFmodel.bonus=[MaxModel.bouns floatValue];

        self.baseWFmodel.yinli=[MaxModel.yinli floatValue];
        
        self.botomLabel.text = [NSString stringWithFormat:@"若中奖，奖金%@元,可盈利%@元",MaxModel.bouns,MaxModel.yinli];
        
        self.baseWFmodel.profitChaseAwardAmount=GetRealFloatNum((self.baseWFmodel.bonus/self.baseWFmodel.multiple));

    }else{//无数据
        self.botomLabel.text = [NSString stringWithFormat:@"若中奖，奖金--元,可盈利--元"];
    }
    if (self.baseWFmodel.stakeNumber == 0) {
        self.botomLabel.text = [NSString stringWithFormat:@"若中奖，奖金0元,可盈利0元"];
    }
}

#pragma mark --------------------- timer
- (void)setUpTimer{
    [self stopTimer];

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(setTimerLabelInfo) userInfo:nil repeats:YES];
    self.timer = timer;
    [[NSRunLoop mainRunLoop ] addTimer:timer forMode:NSRunLoopCommonModes];
}
- (void)setTimerLabelInfo{
    [self.activityIndicator stopAnimating];
    if (self.time == 0) {
        [self loadIssueData:^(BOOL result) {

        }];
      

        
    }
    if (self.time<1) { return;}
    self.time --;
    NSString *hour = [NSString stringWithFormat:@"%.2d",self.time /3600];
    NSString *min = [NSString stringWithFormat:@"%.2d",(self.time - [hour intValue]*3600)/60];
    NSString *sec = [NSString stringWithFormat:@"%.2d",self.time%60];
    NSString *str  = [NSString stringWithFormat:@"%@:%@:%@ ",hour,min,sec];
    NSString *danjishiStr = @"";
    NSString *issueNumberStr = @"";
    if (self.IssueNumber.length>8&&[MCMathUnits isNeedCut:self.baseWFmodel.LotteryID]&&[self.baseWFmodel.LotteryID isEqualToString:@"50"]) {
        issueNumberStr = [self.IssueNumber substringFromIndex:8];
        
    }else{
        issueNumberStr = self.IssueNumber;
    }
    danjishiStr = [NSString stringWithFormat:@"%@ 期 截止时间 %@",issueNumberStr,str];
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:danjishiStr];
    [attributeString addAttributes:@{NSForegroundColorAttributeName:MC_THEME_COLOR,NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(0, issueNumberStr.length)];
     [attributeString addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(danjishiStr.length -str.length, str.length)];
    self.btnDaojishi.attributedText = attributeString;
    
    CGFloat width =  ceil([danjishiStr boundingRectWithSize:CGSizeMake(MAXFLOAT, 18) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} context:nil].size.width);
    
    [self.labelBonusDetail mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.labelDataDaojishi.mas_right);
        make.centerY.equalTo(self.labelDataDaojishi);
        make.width.equalTo(@(G_SCREENWIDTH - width - 20));
    }];
}


- (void)loadHistoryIssueData{

    WS(wself);

    if ([self.baseWFmodel.LotteryID isEqualToString:@"50"]) {
        _mmcHistoryIssueDetailAPIModel = [[MCMmcIssueDetailAPIModel alloc] init];
        _mmcHistoryIssueDetailAPIModel.Page = 1;
        _mmcHistoryIssueDetailAPIModel.Size = 1;
        _mmcHistoryIssueDetailAPIModel.LotteryCode = @"50";
        [_mmcHistoryIssueDetailAPIModel refreashDataAndShow];
        _mmcHistoryIssueDetailAPIModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {

        };
        _mmcHistoryIssueDetailAPIModel.callBackSuccessBlock = ^(id manager) {

            NSArray *arr = manager;
            if (arr.count >0) {
                wself.noDatalabel.hidden = YES;
                [wself stopHistoryTimer];
                NSArray *arrT = [arr[0][@"CzNum"] componentsSeparatedByString:@","];
                wself.historyView.lastHistoryBallArray=arrT;

            }else{
                [wself stopHistoryTimer];
                wself.noDatalabel.hidden = NO;
            }
        };
    }else{
        _historyIssueDetailAPIModel = [[MCHistoryIssueDetailAPIModel alloc] init];
        _historyIssueDetailAPIModel.Page = 1;
        _historyIssueDetailAPIModel.Size = 1;
        _historyIssueDetailAPIModel.LotteryCode = self.baseWFmodel.LotteryID;
        [_historyIssueDetailAPIModel refreashDataAndShow];
        _historyIssueDetailAPIModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
            
        };
        _historyIssueDetailAPIModel.callBackSuccessBlock = ^(id manager) {
            NSArray *arr = manager;
            if (arr.count >0) {
                wself.noDatalabel.hidden = YES;

                NSArray *arrT = [arr[0][@"CzNum"] componentsSeparatedByString:@","];
                wself.historyView.lastHistoryBallArray=arrT;
               
                
            }else{
                [wself stopHistoryTimer];
                wself.noDatalabel.hidden = NO;
            }
        };
    }

}
- (void)loadFistData{
    {
        
        WS(wself);
        
        if ([self.baseWFmodel.LotteryID isEqualToString:@"50"]) {
            _mmcHistoryIssueDetailAPIModel = [[MCMmcIssueDetailAPIModel alloc] init];
            _mmcHistoryIssueDetailAPIModel.Page = 1;
            _mmcHistoryIssueDetailAPIModel.Size = 1;
            _mmcHistoryIssueDetailAPIModel.LotteryCode = @"50";
            [_mmcHistoryIssueDetailAPIModel refreashDataAndShow];
            _mmcHistoryIssueDetailAPIModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
                
            };
            _mmcHistoryIssueDetailAPIModel.callBackSuccessBlock = ^(id manager) {
                
                NSArray *arr = manager;
                if (arr.count >0) {
                    wself.noDatalabel.hidden = YES;
                    [wself stopHistoryTimer];
                    NSArray *arrT = [arr[0][@"CzNum"] componentsSeparatedByString:@","];
                    wself.historyView.lastHistoryBallArray=arrT;
                    
                }else{
                    [wself stopHistoryTimer];
                    wself.noDatalabel.hidden = NO;
                }
            };
        }else{
            _historyIssueDetailAPIModel = [[MCHistoryIssueDetailAPIModel alloc] init];
            _historyIssueDetailAPIModel.Page = 1;
            _historyIssueDetailAPIModel.Size = 1;
            _historyIssueDetailAPIModel.LotteryCode = self.baseWFmodel.LotteryID;
            [_historyIssueDetailAPIModel refreashDataAndShow];
            _historyIssueDetailAPIModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
                
            };
            _historyIssueDetailAPIModel.callBackSuccessBlock = ^(id manager) {
                NSArray *arr = manager;
                
                if (arr.count >0) {
                    wself.noDatalabel.hidden = YES;
                    if ([wself.IssueNumber integerValue] - [arr[0][@"CzPeriod"] integerValue] == 1) {
                        [wself stopHistoryTimer];
                        
                    }
                    
                    NSArray *arrT = [arr[0][@"CzNum"] componentsSeparatedByString:@","];
                    wself.historyView.lastHistoryBallArray=arrT;
                    
                    
                }else{
                    [wself stopHistoryTimer];
                    wself.noDatalabel.hidden = NO;
                }
            };
        }
        
    }
}

- (void)stopTimer{
    //关闭定时器
    [self.timer setFireDate:[NSDate distantFuture]];
    
    [self.timer invalidate];
    
    self.timer = nil;
    
}



/*
 * 选择其中某一个玩法
 */

-(void)selectLotteryKindWithTag:(MCBasePWFModel*)baseWFmodel{

    self.baseWFmodel = baseWFmodel;
    /**圆角分模式*/
    self.baseWFmodel.yuanJiaoFen=1;
    /**奖金*/
    self.baseWFmodel.bonus=0;
    /**倍数*/
    self.baseWFmodel.multiple=1;
    /**金额*/
    self.baseWFmodel.payMoney=0;
    /**注数*/
    self.baseWFmodel.stakeNumber=0;
    /**盈利*/
    self.baseWFmodel.yinli=0;
    
    [self.alertView.msBtn setTitle:@"元  模式" forState:UIControlStateNormal];

    /*
     * 2018年09月21日   ======  圆角分需求
     */
    NSString * type = [MCPullMenuTool GetSelectedYuanJiaoFen:self.lotteriesTypeModel.LotteryID];
    
    if ([type isEqualToString:@"元  模式"]) {
        self.baseWFmodel.yuanJiaoFen=1;
        [self.alertView.msBtn setTitle:type forState:UIControlStateNormal];
    }else if ([type isEqualToString:@"角  模式"]){
        self.baseWFmodel.yuanJiaoFen=0.1;
        [self.alertView.msBtn setTitle:type forState:UIControlStateNormal];
    }else if ([type isEqualToString:@"分  模式"]){
        self.baseWFmodel.yuanJiaoFen=0.01;
        [self.alertView.msBtn setTitle:type forState:UIControlStateNormal];
    }else if ([type isEqualToString:@"厘  模式"]){
        self.baseWFmodel.yuanJiaoFen=0.001;
        [self.alertView.msBtn setTitle:type forState:UIControlStateNormal];
    }
    
   
    
    self.alertView.btTF.text=@"1";
    [self.alertView.moneyBtn setTitle:@"1982.0.0" forState:UIControlStateNormal];
    /**彩种ID*/
    self.baseWFmodel.LotteryID=self.lotteriesTypeModel.LotteryID;
    self.baseWFmodel.czRebate=self.lotteriesTypeModel.MaxRebate;
    self.baseWFmodel.czTZRebate=self.lotteriesTypeModel.BetRebate;
    self.baseWFmodel.SaleState=self.lotteriesTypeModel.SaleState;
    /**彩种名称*/
    self.baseWFmodel.czName=self.lotteriesTypeModel.name;
    self.lotteriesTypeModel.playOnlyNum=self.baseWFmodel.playOnlyNum;
    self.lotteriesTypeModel.typeId=self.baseWFmodel.typeId;
    
    //【021需求】腾讯分分彩 台湾五分彩 北京时时彩 大小单双 只能混合投注
    //【026需求】只要57
    if ([self.baseWFmodel.LotteryID isEqualToString:@"57"]&&[self.baseWFmodel.typeId isEqualToString:@"9"]) {
        self.baseWFmodel.mutex=@"3";
    }
//    if (([self.baseWFmodel.czName isEqualToString:@"腾讯分分彩"]||[self.baseWFmodel.czName isEqualToString:@"台湾五分彩"]||[self.baseWFmodel.czName isEqualToString:@"北京时时彩"])&&[self.baseWFmodel.typeName isEqualToString:@"大小单双"]) {
//        if ([self.baseWFmodel.LotteryID isEqualToString:@"48"]) {
//
//        }else{
////            腾讯分分彩（57）/北京时时彩/台湾五分彩：大小单双的所有玩法应去掉混合购买​​效果。
//           self.baseWFmodel.mutex=@"3";
//        }
//    }
    
    
    
    [self setWFPlayAward];
    
    [self setBetListMarry];
    
    [MCPullMenuTool SaveSelectedLotteryID:self.lotteriesTypeModel.LotteryID andPlayCode:self.lotteriesTypeModel.playOnlyNum];
    
    
//    /*
//     * 2018年09月21日-圆角分需求
//     */
//    [MCPullMenuTool SaveSelectedLotteryID:self.lotteriesTypeModel.LotteryID  andYuanJiaoFen:self.yuanJiaoFenType];



    
    if ([self.baseWFmodel.filterCriteria isEqualToString:@"2"]) {
        self.isDanShi = YES;
        [self.alertView showStackWindow];
    }else{
        self.isDanShi = NO;
        if (self.isDanShi) {
        }else{
            [self.alertView hideStackWindow];
        }
        
    }
    
    
    if ([baseWFmodel.isMachineSelectEnabled isEqualToString:@"0"]) {
        self.randomBtn.enabled = NO;
    } else {
        self.randomBtn.enabled = YES;
    }
    
    NSString *str = [NSString stringWithFormat:@"%@_%@",baseWFmodel.typeName,baseWFmodel.name];
    CGFloat fontSize = 0;
    if (str.length>12) {
        fontSize = 11;
    }else if (str.length>10){
        fontSize = 12;
    }else{
        fontSize = 14;
    }
    self.btnPCatergy.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    [self.btnPCatergy setTitle:str forState:UIControlStateNormal];
    
    
    if (baseWFmodel == nil) {
        return;
    }
    //改变玩法发出通知
    [[NSNotificationCenter defaultCenter] postNotificationName:PickBaseViewControllerChangeErJiNotification object:nil userInfo:@{@"baseModel":baseWFmodel}];
    
    if (_baseTableView) {
        [_baseTableView reloadData];
    }
    //延迟0.1秒是为了让Cell初始化完成
    [self performSelector:@selector(MC_PICKNUMBERVC_INIT) withObject:nil afterDelay:0.1];
    
}
- (void)loadIssue{
    [self loadIssueData:^(BOOL result) {
        
    }];
    [self setUpHistoryTimer];
}
#pragma mark --------------------- load data
- (void)loadIssueData:(Compelete)compeletion{
    

    
    self.bgtopView.hidden = NO;
    if ([self.baseWFmodel.LotteryID isEqualToString:@"50"]){
        self.bgtopView.hidden = YES;
        if (@available(iOS 11.0, *)) {
            self.baseTableView.contentInset = UIEdgeInsetsMake(MC_REALVALUE(-40), 0, 20, 0);
        } else {
            self.baseTableView.contentInset = UIEdgeInsetsMake(MC_REALVALUE(0), 0, 20, 0);
        }
       
        return;//秒秒彩不调用倒计时
    }else{
        if (@available(iOS 11.0, *)) {
            if (self.baseWFmodel.lineH *[self.baseWFmodel.lineCount intValue] >= G_SCREENHEIGHT - 64 - 40 - MC_REALVALUE(40) - 69 - 20 ) {
                self.baseTableView.contentInset = UIEdgeInsetsMake(40, 0, 20, 0);
            } else {
                if (![self.baseWFmodel.filterCriteria isEqualToString:@"2"]) {
                    self.baseTableView.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
                }
            }
            
        }else{
           self.baseTableView.contentInset = UIEdgeInsetsMake(MC_REALVALUE(40), 0, 20, 0);
        }
        [self.btnDaojishi addSubview:self.activityIndicator];
        [self.activityIndicator startAnimating];
        
        MCIssueModel *issueModel = [[MCIssueModel alloc] init];
        issueModel.lotteryNumber = [self.lotteriesTypeModel.LotteryID intValue];
        [issueModel refreashDataAndShow];
        self.issueModel = issueModel;
        __weak typeof(self) weakSelf = self;
        issueModel.callBackSuccessBlock = ^(id manager) {
            
            MCIssueModel *model = [MCIssueModel mj_objectWithKeyValues:manager];
            weakSelf.time= model.RemainTime;
            weakSelf.IssueNumber=model.IssueNumber;
            weakSelf.btnRefreashIssueNumber.hidden=YES;
            
            if (weakSelf.IssueNumber.length>0 && weakSelf.time > 0) {
                weakSelf.lastString = [NSString stringWithFormat:@"距%@期截止:",model.IssueNumber];
                [weakSelf setUpTimer];
                compeletion(YES);
                [weakSelf setUpHistoryTimer];

            }else{
                
                [self loadIssueData:^(BOOL result) {
                    //            if (!result) {
                    //                [self openFailedIssue];
                    //            }
                }];
//                [weakSelf.activityIndicator stopAnimating];
//                weakSelf.btnDaojishi.text = [NSString stringWithFormat:@"获取期号失败"];
//                weakSelf.btnRefreashIssueNumber.hidden=NO;
//                compeletion(NO);
                
            }

            
        };
        
        issueModel.callBackFailedBlock=^(id manager, NSString *errorCode){
            [self loadIssueData:^(BOOL result) {
                //            if (!result) {
                //                [self openFailedIssue];
                //            }
            }];
//            weakSelf.btnRefreashIssueNumber.hidden=NO;
//            compeletion(NO);
            
        };
        
    }
}
//-(void)openFailedIssue{}
- (void)loadData{
    
    /*
     *  获取余额
     */
    //单例的思考，哪些可以用成单例
//    MCUserMoneyModel * userMoneyModel=[MCUserMoneyModel sharedMCUserMoneyModel];
//
//    userMoneyModel.isNeedLoad=NO;
    self.playOnlyNum = [MCPullMenuTool GetSelectedPlayCodeWithLotteryID:self.lotteriesTypeModel.LotteryID];

    
    /*
     *  默认玩法
     */
//    [self selectLotteryKindWithTag:[MCPullMenuViewController Get_DefaultDicWithID:self.lotteriesTypeModel.LotteryID and:self.palyCode]];
    [self selectLotteryKindWithTag:[MCPullMenuViewController Get_DefaultDicWithID:self.lotteriesTypeModel.LotteryID andPlayOnlyNum:self.playOnlyNum]];
    
    
    self.baseWFmodel.maxAwardAmount=nil;
    self.baseWFmodel.minAwardAmount=nil;
   
    /*
     *   单挑单期 最高奖金
     */
    MCMaxbonusModel *bonusModel = [[MCMaxbonusModel alloc] init];
    bonusModel.lotteryNumber = [self.lotteriesTypeModel.LotteryID intValue];
    self.bonusModel = bonusModel;
    [bonusModel refreashDataAndShow];
    /*
     *   玩法奖金
     */
    MCGetplayawardModel *playawardModel = [[MCGetplayawardModel alloc] init];
    playawardModel.lotteryNumber = [self.lotteriesTypeModel.LotteryID intValue];
    [playawardModel refreashDataAndShow];
    self.playawardModel = playawardModel;
    __block NSMutableArray *boModelArray = nil;
    __weak typeof(self)wself = self;
//        dispatch_group_t group = dispatch_group_create();
//        dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//        dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
//        dispatch_group_async(group, quene, ^{
    
        bonusModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
//              NSLog(@"complete task 1");
            
//               dispatch_semaphore_signal(semaphore);
        };
        bonusModel.callBackSuccessBlock = ^(id manager) {
            [wself.boModelArray removeAllObjects];
            boModelArray = [MCMaxbonusModel mj_objectArrayWithKeyValuesArray:manager];
            
          
            wself.boModelArray = boModelArray;
//              NSLog(@"complete task 1");
//              dispatch_semaphore_signal(semaphore);
        };
    
//        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
//      });
    
//        dispatch_group_async(group, quene, ^{
    
            playawardModel.callBackSuccessBlock = ^(id manager){
    
                wself.playModelArray = [MCGetplayawardModel mj_objectArrayWithKeyValuesArray:manager];

//                dispatch_semaphore_signal(semaphore);
    
                [wself setWFPlayAward];
                

            };
            playawardModel.callBackFailedBlock = ^( id manager, NSString *errorCode) {

//                
//                dispatch_semaphore_signal(semaphore);
            };
//        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
//       });
    
    
//        dispatch_group_notify(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//            
//            NSLog(@"完成了网络请求，不管网络请求失败了还是成功了。");
//
//        });
 
    
    
    
    
}
#pragma mark-----------设置玩法奖金
-(void)setWFPlayAward{
    for (MCGetplayawardModel * model in self.playModelArray) {
        if ([model.PlayCode isEqualToString:[NSString stringWithFormat:@"%@%@",self.baseWFmodel.LotteryID,self.baseWFmodel.methodId]]) {
            
            NSDictionary *dic1= model.AwardLevelInfo[0];
            if (model.AwardLevelInfo.count>1) {
            
                self.baseWFmodel.maxAwardAmount=[self getMaxandMinWithArr:model.AwardLevelInfo][@"MAX"];
                self.baseWFmodel.minAwardAmount=[self getMaxandMinWithArr:model.AwardLevelInfo][@"MIN"];
            
            }else{
                self.baseWFmodel.maxAwardAmount=dic1[@"AwardAmount"];
                self.baseWFmodel.minAwardAmount=nil;
            }
        }
    }
    [self relayOutAlertViewData];
}

-(NSDictionary *)getMaxandMinWithArr:(NSArray *)arr{

    double max=[arr[0][@"AwardAmount"] doubleValue];
    double min=[arr[0][@"AwardAmount"] doubleValue];
    
    for (NSDictionary *temp in arr) {

        if (max<[temp[@"AwardAmount"] doubleValue]) {
            max=[temp[@"AwardAmount"] doubleValue];
        }
        if (min>[temp[@"AwardAmount"] doubleValue]) {
            min=[temp[@"AwardAmount"] doubleValue];
        }
    }
    
    NSDictionary * dic=@{
                         @"MAX":GetRealFloatNum(max),
                         @"MIN":GetRealFloatNum(min)
                         };
    
    return dic;
    
}


#pragma mark----------设置列表返点数据
-(void)setBetListMarry{
    
    self.baseWFmodel.shangHuRebate = [[NSUserDefaults standardUserDefaults] objectForKey:MerchantMaxRebate];
    self.baseWFmodel.shangHuMinRebate = [[NSUserDefaults standardUserDefaults] objectForKey:MerchantMinRebate];
    self.baseWFmodel.XRebate = [[NSUserDefaults standardUserDefaults] objectForKey:MerchantXRebate];
    self.baseWFmodel.Mode=[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:MerchantMode]];
    self.baseWFmodel.userRegisterRebate=[[NSUserDefaults standardUserDefaults] objectForKey:@"MyRebate"];
    if (self.baseWFmodel.XRebate&&self.baseWFmodel.shangHuRebate&&self.baseWFmodel.userRegisterRebate&&self.baseWFmodel.czRebate&&self.baseWFmodel.czTZRebate&&self.baseWFmodel.shangHuMinRebate) {
        
        _betRebateArray=[MCDataTool GetShowBetRebateMarryWithModel:self.baseWFmodel];
        
        //默认展示的返点
        MCShowBetModel * betModel=_betRebateArray[0];
        self.baseWFmodel.userSelectedRebate=betModel.BetRebate;
        self.baseWFmodel.showRebate=betModel.showRebate;
        [self.alertView.moneyBtn setTitle:betModel.showRebate forState:UIControlStateNormal];
        
    }
    [self setDefaultBottomModeAndRebate];
}

- (void)setDefaultBottomModeAndRebate{
    NSMutableArray * marr=[[NSMutableArray alloc]init];
    int mode= [self.baseWFmodel.Mode intValue];
    [marr addObject:@"元  模式"];
    if ((mode&2) ==2 ) {
        [marr addObject:@"角  模式"];
    }
    if ((mode&1) ==1 ) {
        [marr addObject:@"分  模式"];
    }
    if ((mode&8) ==8 ) {
        [marr addObject:@"厘  模式"];
    }
    //列表负值默认值
    [MCMSPopView alertInstance].dataArray = marr;
    //列表负值
    [MCMoneyPopView alertInstance].dataArray = _betRebateArray;
}

//修改了返点
-(void)setUserSelectedRebate:(NSNotification *)noti{
    
    NSDictionary *dic = noti.userInfo;
    MCShowBetModel * model = dic[@"MCShowBetModel"];
    self.baseWFmodel.userSelectedRebate=model.BetRebate;
    self.baseWFmodel.showRebate=model.showRebate;
    
    [self relayOutAlertViewData];
}


/**需要被覆盖的方法*/

#pragma mark - 需要被覆盖的方法
- (void)setUpUI{
    
}
- (void)randomBtnClick{
    self.randomBtnSelected = YES;
    
}
- (void)conferencePayTheSelectedNumbers{
    
}
- (void)clearAllButtonClick{
    
}

- (void)addNumberToShoppingCar:(BOOL)isShow{
    
}

- (void)payTheSelectedNumbers{
    
}

//Push到菜种选择列表  将下拉弹回 ->在子类重写
-(void)pullLotteryRecordViewToTop{
    
}
-(void)MC_PICKNUMBERVC_INIT{
    
}

#pragma mark - getter and setter

- (NSMutableArray *)selectedCardArray{
    if (_selectedCardArray == nil) {
        _selectedCardArray = [NSMutableArray array];
    }
    return _selectedCardArray;
}

- (NSMutableArray *)boModelArray{
    if (_boModelArray == nil) {
        _boModelArray = [NSMutableArray array];
    }
    return _boModelArray;
}
-(UIActivityIndicatorView *)activityIndicator{
    
    if (!_activityIndicator) {
        
        _activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleWhite)];
        //设置小菊花的frame
        _activityIndicator.frame= CGRectMake(G_SCREENWIDTH * 0.5 - MC_REALVALUE(20) - MC_REALVALUE(78), -20, MC_REALVALUE(40), MC_REALVALUE(40));
        //设置小菊花颜色
        //        _activityIndicator.color = RGB(100, 100, 100);
        //设置背景颜色
        _activityIndicator.backgroundColor = [UIColor clearColor];
        //刚进入这个界面会显示控件，并且停止旋转也会显示，只是没有在转动而已，没有设置或者设置为YES的时候，刚进入页面不会显示
        [_activityIndicator setHidesWhenStopped:YES]; //当旋转结束时隐藏
    }
    return _activityIndicator;
}




//
//- (MCHistoryIssueDetailAPIModel *)historyIssueDetailAPIModel{
//    if (_historyIssueDetailAPIModel == nil) {
//        _historyIssueDetailAPIModel = [[MCHistoryIssueDetailAPIModel alloc] init];
//        _historyIssueDetailAPIModel.Page = 1;
//        _historyIssueDetailAPIModel.Size = 1;
//        _historyIssueDetailAPIModel.LotteryCode = self.baseWFmodel.LotteryID;
//        [_historyIssueDetailAPIModel refreashDataAndShow];
//    }
//    return _historyIssueDetailAPIModel;
//}
//
//- (MCMmcIssueDetailAPIModel *)mmcHistoryIssueDetailAPIModel{
//    if (_mmcHistoryIssueDetailAPIModel == nil) {
//        _mmcHistoryIssueDetailAPIModel = [[MCMmcIssueDetailAPIModel alloc] init];
//        _mmcHistoryIssueDetailAPIModel.Page = 1;
//        _mmcHistoryIssueDetailAPIModel.LotteryCode = self.baseWFmodel.LotteryID;
//        [_mmcHistoryIssueDetailAPIModel refreashDataAndShow];
//    }
//    return _mmcHistoryIssueDetailAPIModel;
//}

@end
